<template>
  <div class="forget_component">
      <div class="three">
          <span class="sure" style="color:#ff552e">
              <span>1</span>
              <span>确认账号</span>
          </span>
          <span class="line"></span>
          <span class="user" :style="this.submitType > 1 ? 'color: #ff552e' : 'color: #ccc'">
              <span :style="this.submitType > 1 ? '' : 'background: #ccc'">2</span>
              <span>身份验证</span>
          </span>
          <span class="line"></span>
          <span class="pas" :style="this.submitType > 2 ? 'color: #ff552e' : 'color: #ccc'">
              <span :style="this.submitType > 2 ? '' : 'background: #ccc'">3</span>
              <span>重置密码</span>
          </span>
      </div>
      <div class="main">
        <Process ref="ruleForm" :submitType="submitType" @success="success" @error="error" :submitClick="submitClick"></Process>
      </div>
      <Canvas :style="submitType < 2 ? '' : 'visibility:hidden'" @onSuccess="onSuccess" @onError="onError"></Canvas>
      <div class="submit" @click="submit">{{ submitType == 2 ? '下一步' : '提交' }}</div>
  </div>
</template>

<script>
import Canvas from './canvas'
import Process from './process'
export default {
  components: {
    Canvas,
    Process
  },
  data () {
    return {
      submitType: false, // 是否可以提交进入下一步
      formType: false, // 表单验证
      submitClick: false
    }
  },
  methods: {
    submit () {
      this.submitClick = !this.submitClick
      if (this.submitType === 3) {
        return
      }
      if (this.submitType === 2 && this.$refs.ruleForm.user.phoneCode) {
        this.submitType = 3
        return
      }
      if (this.formType && this.submitType) {
        this.submitType = 2
      }
    },
    success (val) {
      this.formType = val
    },
    error (val) {
      console.log(val, 'error')
      this.formType = val
    },
    onSuccess () {
      this.submitType = true
    },
    onError () {
      this.submitType = false
    }
  }
}
</script>

<style lang="less" scoped>
.forget_component {
    text-align: center;
    .submit {
        width: 276px;
        height: 43px;
        margin: 30px auto;
        position: absolute;
        cursor: pointer;
        transform: translate(-58%, 0%);
        left: 50%;
        background: #ff552e;
        line-height: 43px;
        text-align: center;
        color: #fff;
    }
    .three {
        text-align: center;
        span {
            display: inline-block;
            :first-child {
                display: block;
                width: 28px;
                height: 28px;
                background: #ff552e;
                margin: 0 auto;
                border-radius: 50%;
                color: #fff;
                line-height: 28px;
                text-align: center;
                margin-bottom: 10px;
            }
        }
        .line {
            display: inline-block;
            width: 137px;
            height: 2px;
            background: #ccc;
            position: relative;
            margin: 32px 9px;
            bottom: 4px;
        }
    }
    .main {
        text-align: center;
        /deep/.el-form{
            width: 360px;
            height: 36px;
            position: absolute;
            left: 46%;
            transform: translate(-50%, 169%);
        }
    }
}
</style>
